package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserGift;
import com.qinggeng.project.system.service.IUserGiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 用户礼品Controller
 *
 * @author qinggeng
 * @date 2020-07-15
 */
@RestController
@RequestMapping("/system/userGift")
public class UserGiftController extends BaseController
{
    @Autowired
    private IUserGiftService userGiftService;

    /**
     * 查询用户礼品列表
     */
    @PreAuthorize("@ss.hasPermi('system:gift:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserGift userGift)
    {
        startPage();
        List<UserGift> list = userGiftService.selectUserGiftList(userGift);
        return getDataTable(list);
    }

    /**
     * 导出用户礼品列表
     */
    @PreAuthorize("@ss.hasPermi('system:gift:export')")
    @Log(title = "用户礼品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserGift userGift)
    {
        List<UserGift> list = userGiftService.selectUserGiftList(userGift);
        ExcelUtil<UserGift> util = new ExcelUtil<UserGift>(UserGift.class);
        return util.exportExcel(list, "gift");
    }

    /**
     * 获取用户礼品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:gift:query')")
    @GetMapping(value = "/{userGiftId}")
    public AjaxResult getInfo(@PathVariable("userGiftId") Long userGiftId)
    {
        return AjaxResult.success(userGiftService.selectUserGiftById(userGiftId));
    }

    /**
     * 新增用户礼品
     */
    @PreAuthorize("@ss.hasPermi('system:gift:add')")
    @Log(title = "用户礼品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserGift userGift)
    {
        return toAjax(userGiftService.insertUserGift(userGift));
    }

    /**
     * 修改用户礼品
     */
    @PreAuthorize("@ss.hasPermi('system:gift:edit')")
    @Log(title = "用户礼品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserGift userGift)
    {
        return toAjax(userGiftService.updateUserGift(userGift));
    }

    /**
     * 删除用户礼品
     */
    @PreAuthorize("@ss.hasPermi('system:gift:remove')")
    @Log(title = "用户礼品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userGiftIds}")
    public AjaxResult remove(@PathVariable Long[] userGiftIds)
    {
        return toAjax(userGiftService.deleteUserGiftByIds(userGiftIds));
    }
}
